package com.cheegu.common.parser.gpsdata.reader;

import com.cheegu.common.parser.gpsdata.DataReader;
import com.cheegu.common.parser.gpsdata.Parser;
import com.cheegu.common.parser.gpsdata.RawDataReader;
import com.cheegu.common.parser.gpsdata.parser.DefaultGpsDataParser;
import com.cheegu.common.parser.gpsdata.pojo.GpsDataEntity;
import com.cheegu.common.parser.gpsdata.reader.raw.TxtRawDataReader;

import java.util.List;
import java.util.stream.Collectors;

public class DefaultGpsDataReader implements DataReader<GpsDataEntity> {
    private Parser<GpsDataEntity> parser;
    private RawDataReader rawDataReader;

    public DefaultGpsDataReader(String path) {
        this.parser = new DefaultGpsDataParser();
        this.rawDataReader = new TxtRawDataReader(path);
    }

    @Override
    public List<GpsDataEntity> read() {
        List<String> rows = rawDataReader.readAsList();
        return rows.stream().map(row -> parser.parse(row)).collect(Collectors.toList());
    }
}
